package com.cqw.order.enums;

import com.cqw.enums.BaseEnum;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-07-12 10:08
 * @Description: 商品分类状态
 */
public enum ItemStateEnum implements BaseEnum {

    ON_LINE(1, "上线"),
    OFF_LINE(0, "下线");


    private final static Map<Integer, ItemStateEnum> typeMap =
            Arrays.stream(ItemStateEnum.values()).collect(Collectors.toMap(ItemStateEnum::code, Function.identity()));

    private final static Map<String, ItemStateEnum> typeByNameMap =
            Arrays.stream(ItemStateEnum.values()).collect(Collectors.toMap(Enum::name, Function.identity()));


    private final Integer code;

    private final String value;


    ItemStateEnum(int code, String value) {
        this.code = code;
        this.value = value;
    }

    /**
     * 通过code获取枚举
     *
     * @param code
     * @return
     */
    public static ItemStateEnum parse(int code) {
        return typeMap.get(code);
    }

    /**
     * 通过value获取枚举
     *
     * @param value
     * @return
     */
    public static ItemStateEnum parse(String value) {
        return typeByNameMap.get(value);
    }

    @Override
    public Integer code() {
        return this.code;
    }

    @Override
    public String value() {
        return this.value;
    }
}
